<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<jsp:include page="/_meta.jsp"/>
<link href="/lib/easyui/themes/default/easyui.css" rel="stylesheet" type="text/css">
<link href="/lib/easyui/themes/icon.css" rel="stylesheet" type="text/css">
<title>用户管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 用户中心 <span class="c-gray en">&gt;</span> 用户管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container" style="width:1400px;margin:20px auto">
	<table id="purchaseTable"></table>
</div>
<jsp:include page="/_footer.jsp"/>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script src="/lib/easyui/jquery.easyui.min.js"></script>
<script src="/lib/easyui/locale/easyui-lang-zh_CN.js"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
$(function(){
	

		
	$.post("GetPurchaseDataServlet",
	function(data)
	{   
		
		json=new Array();
		var js_data=$.parseJSON(data);
		
		for(i=0;i<js_data.length;i++)
			{
			 json[i]={
					pursId:js_data[i].pursId,
					supplyName:js_data[i].supplier.supName,
					operatorName:js_data[i].operator.name,
					purchaseDate:js_data[i].putchaseDate,
					accountpaying:js_data[i].accountPaying,
					accountpayed:js_data[i].accountPaied,
					excuteState:js_data[i].excuteState			
			};
		
			}
		$("#purchaseTable").datagrid({
			onLoadSuccess:function()
			{
				$("a.easyui-linkbutton").linkbutton();
			},
			title:'待处理采购单',
			iconCls:'icon-edit',
			width:1200,
			rownumbers:true,
			AllowPaging:true,
			pagination:true,
			singleSelect:true,
	        data:json,
			columns:[[
				{field:'pursId',title:'采购编码',width:180,align:'center'},
				{field:'supplyName',title:'供应商',width:180
					,align:'center'},
				{field:'operatorName',title:'采购人',width:180
				,align:'center'},
				{field:'purchaseDate',title:'采购日期',width:180,align:'center'},
				{field:'accountpaying',title:'实收金额',width:80,align:'center'},
				{field:'accountpayed',title:'应收金额',width:80,align:'center'},
				{field:'excuteState',title:'执行状态',width:80,align:'center',
					editor:{
						type:'text',
						options:{
							on: 'P',
							off: ''
						}
					}
				},
				{field:'operation',title:'操作',width:80,align:'center',
					formatter:function(value,row,index){
						return '<a class="easyui-linkbutton" iconCls="icon-redo" onclick=stockin('+index+') >入库</a>' ;		
					}
					}
				
			]],
			onBeforeEdit:function(index,row){
				row.editing = true;
				updateActions(index);
			},
			onAfterEdit:function(index,row){
				row.editing = false;
				updateActions(index);
			},
			onCancelEdit:function(index,row){
				row.editing = false;
				updateActions(index);
			}
		});	
	});
	
	
});
/*用户-添加*/
function member_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*用户-查看*/
function member_show(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*用户-停用*/
function member_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
				$(obj).remove();
				layer.msg('已停用!',{icon: 5,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

//入库
function stockin(index)
{ 
	$('#purchaseTable').datagrid('selectRow',index);
	var row=$('#purchaseTable').datagrid('getSelected');
	if(row)
		{
	layer_show("入库操作","stocklistin.jsp?pursId="+row.pursId,950,800);
		}
	}

/*用户-启用*/
function member_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
				$(obj).remove();
				layer.msg('已启用!',{icon: 6,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});
	});
}
/*用户-编辑*/
function member_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*密码-修改*/
function change_password(title,url,id,w,h){
	layer_show(title,url,w,h);	
}
/*用户-删除*/
function member_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '',
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}
</script> 
</body>
</html>
